import { Component, OnInit, ViewChild } from '@angular/core';
import { environment } from '../../../../environments/environment';
import { TableCheckPageComponent } from '../../../layout/components/tableCheckPage.component';

@Component({
    selector: 'app-weekplanworkshop',
    templateUrl: './weekPlanWorkshop.component.html',
    styleUrls: ['./weekPlanWorkshop.component.less']
})

export class WeekPlanWorkshopComponent implements OnInit {
    @ViewChild('tcp', { static: true }) tcp: TableCheckPageComponent;
    searchParam: any = {};
    headData = [];
    plainData = [];
    operaList: any = [
        { addModal: false },
        { editModal: false },
        { delModal: false }
    ];
    tempData = [];
    treeNodeStyle = { 'max-width': '300px', 'max-height': '400px', 'overflow-y': 'auto', 'overflow-x': 'hidden' };
    apiUrl: any = {};

    constructor() { }

    ngOnInit() {
        this.headData = [
            { "name": "周次", "width": "20%" },
            { "name": "月份", "width": "20%" },
            { "name": "文件名", "width": "" },
            { "name": "上传时间", "width": "20%" }
        ];
        this.plainData = ["week", "month", "nameLink", "operTime"];
        this.apiUrl.add = environment.project + '/czWeekplan/add';
        this.apiUrl.edit = environment.project + '/czWeekplan/update';
        this.apiUrl.del = environment.project + '/czWeekplan/delete';
        this.loadList();
    }
    loadList() {
        this.tcp.loadList(environment.project + '/czWeekplan/query', '');
    }
    search() {
        let params = '';
        if (this.searchParam.fileName) {
            params += '&fileName=' + this.searchParam.fileName;
        }
        if (this.searchParam.year) {
            params += '&year=' + new Date(this.searchParam.year.getTime()).getFullYear();
        }
        if (this.searchParam.month) {
            params += '&month=' + Number(new Date(this.searchParam.month.getTime()).getMonth() + 1);
        }
        this.tcp.loadList(environment.project + '/czWeekplan/query', params);
    }
    modalShow(type) {
        this.tempData = this.tcp.getAllData();
        this.operaList[type] = true;
    }
    modalHide(type) {
        this.operaList[type] = false;
    }
}
